#pragma once
#include "Property.h"
#include "PropertyIDs.h"
#include "GameObject.h"
#include "../Common/ArrayBuffer.h"

template<typename F>
struct VisitAllClass
{
	VisitAllClass(const F& fun) : m_fun(fun)
	{

	}

	template<typename T>
	bool operator()(T& v)
	{
		m_fun(v);
		return true;
	}

private:
	F m_fun;
};


template<typename F> 
VisitAllClass<F> visitAll(const F& fun)
{
	return VisitAllClass<F>(fun);
}


template<typename F>
struct visitAllExceptClass
{
	visitAllExceptClass(WorldObject*obj,const F& fun) : m_fun(fun)
	{

	}

	template<typename T>
	bool operator()(T& v)
	{
		if (v == m_obj)
			return true;

		m_fun(v);
		return true;
	}

private:
	WorldObject* m_obj;
	F m_fun;
};

template<typename F> 
visitAllExceptClass<F> visitAllExcept(WorldObject*obj,const F& fun)
{
	return visitAllExceptClass<F>(obj,fun);
}


struct BuilldPropertyVistor
{
	BuilldPropertyVistor(ArrayBuffer& b) : m_buffer(b)
	{

	}

	bool operator()(int pid, uint32 p)
	{
		m_buffer << p;
		return true;
	}

	bool operator()(int pid, float p)
	{
		m_buffer << p;
		return true;
	}

	bool operator()(int pid, const char* p)
	{
		std::string str(p);
		m_buffer << str;
		return true;
	}

private:
	ArrayBuffer& m_buffer;
};